package leetcode_堆;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * 超过阈值的最少操作数 II
 * 算法: 优先队列
 *
 * @author yezh
 * @date 2025/1/15 15:15
 */
public class _3066 {

    public int minOperations(int[] nums, int k) {
        Queue<Long> q = new PriorityQueue<>(Comparator.comparingLong(a -> a));
        for (int num : nums) q.offer((long) num);
        int ans = 0;
        while (q.peek() < k) {
            long x = q.poll(), y = q.poll();
            q.offer(Math.min(x, y) * 2 + Math.max(x, y));
            ++ans;
        }
        return ans;
    }

}
